﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Data.Objects;

namespace Arch.EF.Services
{
    public class OperationProxyResolverAttribute : Attribute, IOperationBehavior
    {
        public void AddBindingParameters(
                      OperationDescription description,
                      BindingParameterCollection parameters)
        {
        }

        public void ApplyClientBehavior(
                      OperationDescription description,
                      ClientOperation proxy)
        {
            DataContractSerializerOperationBehavior
               operationBehavior =
                  description.Behaviors.Find<DataContractSerializerOperationBehavior>();
            operationBehavior.DataContractResolver = new ProxyDataContractResolver();
        }

        public void ApplyDispatchBehavior(
                       OperationDescription description,
                       DispatchOperation dispatch)
        {
            DataContractSerializerOperationBehavior
               operationBehavior =
                  description.Behaviors.Find<DataContractSerializerOperationBehavior>();
            operationBehavior.DataContractResolver = new ProxyDataContractResolver();
        }

        public void Validate(OperationDescription description)
        {
        }
    }
}
